package com.vng.zing.survey.utility;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author kienpd
 */
public class TimeDay {

    public static Date getDate(int time) {
        try {
            String pattern = "dd/MM/yyyy";
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date((long)time*1000L));
           
            Date date;
            date = format.parse(dateFormat.format(cal.getTime()));
            return date;
        } catch (ParseException ex) {
            Logger.getLogger(TimeDay.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;

    }

    public static Date nextDay(Date date) {

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, 1);

        return cal.getTime();
    }

    public static Date beforDay(Date date) {
         
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, -1);
        return cal.getTime();
    }

    public static String convertDateToString(Date date) {
         DateFormat dateFormat = new SimpleDateFormat("dd/MM");
         Calendar cal = Calendar.getInstance();
         cal.setTime(date);
            
        return dateFormat.format(cal.getTime());
    }
    public static String dateToString(Date date){
    
         DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
         Calendar cal = Calendar.getInstance();
         cal.setTime(date);
            
        return dateFormat.format(cal.getTime());
    
    }

}
